package us.wili.dev.common.model;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by JasonY on 2016/12/21.
 */
public class Pager<T> {

    public final static long DEFAULT_PAGE_NO = 1;
    public final static long DEFAULT_PER_PAGE = 10;

    private Long page;    //当前页码
    private Long total;          //总条数
    private Long count;          //每页条数
    private Collection<T> array;       //返回的数据集合
    private Map<String, Object> extras;

    public Pager() {
    }

    public Pager(Long page, Long count) {
        this.page = page;
        this.count = count;
        this.extras = new HashMap<>();
    }

    public Long getOffset() {
        return (getPage() - 1) * getCount();
    }

    public Long getTotalPageNo() {
        return total % getCount() == 0 ? total / getCount() : total / getCount() + 1;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public Collection<T> getArray() {
        return array;
    }

    public void setArray(Collection<T> array) {
        this.array = array;
    }

    public Map<String, Object> getExtras() {
        return extras;
    }

    public void setExtras(Map<String, Object> extras) {
        this.extras = extras;
    }

    public Long getPage() {
        return page == null || page <= 0L ? DEFAULT_PAGE_NO : page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public Long getCount() {
        return count == null || count <= 0L ? DEFAULT_PER_PAGE : count;
    }

    public void setCount(long count) {
        this.count = count;
    }
}
